#ifndef __THREAD_H__
#define __THREAD_H__
#include "../../include/type_define.hpp"

#ifdef WIN32
#include <process.h>
typedef HANDLE  THREAD_HANDLE;
class CThread
{
public:
    CThread(void);
public:
    virtual ~CThread(void);

    virtual void ThreadProc(void) = 0;

    bool Start(bool bSuspend);

    void WaitFor(UINT32 dwWaitTime = INFINITE);

    inline THREAD_HANDLE GetThreadHandle(void){return m_hThread;}
    inline UINT32 GetThreadId(void){return m_dwThreadId;}

private:
    static unsigned int _stdcall StaticThreadFunc(void *arg);
protected:
    HANDLE  m_hThread;
    UINT32  m_dwThreadId;
};
#else
#include <pthread.h>
#include <signal.h>
#define INFINITE    0xffffffff
typedef pthread_t   THREAD_HANDLE;
class CThread
{
public:
    CThread(void);
public:
    virtual ~CThread(void);

    virtual void ThreadProc(void) = 0;

    bool Start(bool bSuspend);

    void WaitFor(UINT32 dwWaitTime = INFINITE);

    inline THREAD_HANDLE GetThreadHandle(void){return m_stThread;}
private:
    static void *StaticThreadFunc(void* arg);
protected:
    pthread_t   m_stThread;

};
#endif

#endif
